package com.sptpc.demo.controller;

import com.sptpc.demo.service.IOrderService;
import com.sptpc.demo.vo.OrderWithItemsVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private IOrderService orderService;
//
    @GetMapping("/{id}")
    public OrderWithItemsVo getOrderById1(@PathVariable Long id) {
        return orderService.getOrderById1(id);
    }

    @GetMapping("/{customer}/{id}")
    public OrderWithItemsVo getOrderById(@PathVariable Long id, @PathVariable String customer) {
        return orderService.getOrderById(id,customer);
    }


//    @PostMapping("/")
//    public Order addNewOrder(@RequestBody AddOrderRequest request) {
//        log.info("订单信息:{}", request);
//        // AddOrderRequest -> Order
//        Order order = new Order();
//        BeanUtils.copyProperties(request, order);
//        orderService.addNewOrder(order, request.getItems());
//
//        return order;
//    }
//
//    // get /order/张三
//    @GetMapping("/{customer}")
//    public List<Order> searchOrdersByCustomer(@PathVariable String customer) {
//        return orderService.findOrdersByCustomer(customer);
//    }

}
